﻿<?php
/**
* @version		$Id: view.html.php 9764 2007-12-30 07:48:11Z ircmaxell $
* @package		Joomla
* @subpackage	Poll
* @copyright	Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license		GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/


// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();

jimport( 'joomla.application.component.view');

/**
 * HTML View class for the Poll component
 *
 * @static
 * @package		Joomla
 * @subpackage	Poll
 * @since 1.0
 */
class amapViewadaboldb_force extends JView
{
	var $amap;

	function display($tpl = null)
	{
		if($this->amap->adLoggue)
		{
		$mainframe =& JFactory::getApplication();	
		
			$database =& JFactory::getDBO();
			$document =& JFactory::getDocument();
			$pathway  =& $mainframe->getPathway();

			// Adds parameter handling
			$params = $mainframe->getParams();
			
			// infos abonnement
//			$abonnement = $mainframe->getUserState("amap_abonnement");
//$abonnement=$_POST['nomcontrat'];




$abonnement=$mainframe->getUserState($option.'abonnement_nom');
$statut=$mainframe->getUserState($option.'abonnement_statut');
$ida=$mainframe->getUserState($option.'abonnement_ida');

$query = "SELECT DateDebut, DateFin from amap_abonnement WHERE Nom='$abonnement'";
//echo $query;
$database =& JFactory::getDBO();
$database->setQuery($query);
$database->query(); if ($database->getErrorNum()) {echo 'Error ' . $database->getErrorNum() . ': ' .$database->getErrorMsg();}
$liste=$database->loadRowList();
$premiere=$liste[0][0];
$derniere=$liste[0][1];

//echo "<br>$premiere $derniere</br>";

$query = "INSERT INTO amap_abonnementadherent (NomAbonnement,IDA,PremiereDistribution,DerniereDistribution) VALUES('$abonnement',$ida,'$premiere','$derniere')";
$database =& JFactory::getDBO();
$database->setQuery($query);
$database->query(); //if ($database->getErrorNum()) {echo 'Error ' . $database->getErrorNum() . ': ' .$database->getErrorMsg();}
if ($database->getErrorNum()==1062){echo "Le contat <strong>$abonnement</strong> existe déja, vous pouvez le voir et/ou le modifier en cliquant ci dessous<br>";}
else
{if ($database->getErrorNum()) {echo 'Error ' . $database->getErrorNum() . ': ' .$database->getErrorMsg();}}


//$liste=$database->loadRowList();

//echo"<a href='?view=abocom&ida=$ida&abo=$abonnement'></a>";
//$this->setRedirect('index.php?option=com_amap&view=abocom&ida='.$ida.'&abo='.$abonnement);
//$vue->display();

//return;
//echo"<target='?view=abocom&ida=$ida&abo=$abonnement'>";
echo"<a href='?view=abocom&ida=$ida&abo=$abonnement'>l'ajout du contrat s'est bien passé - cliquer pour le completer</a>";

//echo $abonnement."statut ". $statut;
//echo "<br>hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh<br>";

//print_r($this->amap->formulaire);

//			echo '<p class="amap_legend"><img src="components/com_amap/images/aide.png" style="position:relative;top:6px;margin-right:4px;" />Besoin d\'aide ?</p>';
//			echo '<div id="amap_footer">
//			Pour passer contrat, complétez les informations affichées en indiquant le nombre de paniers que vous souhaitez prendre par livraison et leur taille. Vous inscrivez ensuite la date à laquelle vous souhaitez voir débuter concrètement votre contrat. <br/>  
//			Pour que le contrat soit validé, vous devez  ensuite payer et signer un contrat. 
//			</div>';
		}
//20130923BM
//JRequest::setCmd( 'layout', $template );		
parent::display($tpl);
	}
}
?>
